{ "cells": [ { "cell_type": "markdown", "id": "d240914c", "metadata": {}, "source": [ "## Dictionary Creation" ] }, { "cell_type": "code", "execution_count": 3, "id": "0120aec7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'A': 1, 'B': 2, 'C': 3}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dict1={\n", " 'A':1,\n", " 'B':2,\n", " 'C':3\n", "}\n", "dict1" ] }, { "cell_type": "markdown", "id": "5ad73a37", "metadata": {}, "source": [ "### From range function" ] }, { "cell_type": "code", "execution_count": 6, "id": "43be5f02", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{0: 0, 1: 2, 2: 4, 3: 6}" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "{i:i*2 for i in range(4)}" ] }, { "cell_type": "markdown", "id": "7a7283f7", "metadata": {}, "source": [ "### From Lists" ] }, { "cell_type": "code", "execution_count": 14, "id": "32fa8057", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'A': 1, 'B': 2, 'C': 3}" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list1=['A','B','C']\n", "list2=[1,2,3]\n", "{x:y for x,y in zip(list1,list2)}" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.8" } }, "nbformat": 4, "nbformat_minor": 5 }